import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import '../common/const/app_color_const.dart';
import '../common/const/app_style_const.dart';

class InputField extends StatelessWidget {
  final TextEditingController controller;
  final List<TextInputFormatter>? inputFormatters;
  final String labelText;
  final String hintText;
  final String? helperText;
  final int minLines;
  final int maxLines;
  final int? maxLength;
  final TextInputType keyboardType;
  final bool obscureText;
  final bool readOnly;
  final bool enabled;
  final Widget? suffixIcon;
  final EdgeInsets margin;
  final FocusNode? focusNode;

  const InputField(
      {Key? key,
      required this.controller,
      required this.labelText,
      required this.hintText,
      this.helperText,
      this.minLines = 1,
      this.maxLines = 1,
      this.maxLength,
      this.keyboardType = TextInputType.text,
      this.obscureText = false,
      this.readOnly = false,
      this.enabled = true,
      this.margin = const EdgeInsets.only(bottom: 6.0, top: 6.0),
      this.suffixIcon,
      this.focusNode,
      this.inputFormatters})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: margin,
      child: TextField(
        focusNode: focusNode ?? FocusNode(),
        controller: controller,
        minLines: minLines,
        maxLines: maxLines,
        maxLength: maxLength,
        keyboardType: keyboardType,
        obscureText: obscureText,
        style: inputStyle,
        inputFormatters: inputFormatters,
        readOnly: readOnly,
        enabled: enabled,
        decoration: InputDecoration(
            suffixIcon: suffixIcon,
            enabledBorder: const OutlineInputBorder(
              borderRadius: BorderRadius.all(
                Radius.circular(4),
              ),
              borderSide: borderStyle,
            ),
            focusedBorder: const OutlineInputBorder(
                borderRadius: BorderRadius.all(
                  Radius.circular(4),
                ),
                borderSide: borderStyle),
            isDense: true,
            labelText: "$labelText：",
            labelStyle: inputLabelStyle,
            floatingLabelBehavior: FloatingLabelBehavior.never,
            hintText: hintText,
            hintStyle: inputHintStyle,
            alignLabelWithHint: true,
            helperText: helperText,
            prefixText: "$labelText："),
      ),
    );
  }
}
